import request from "@/utils/request";
import type {
  UserResponseData,
  Records,
  RoleResponseData,
  SetRoleData,
} from "@/api/acl/user/type";
enum API {
  //获取全部已有用户账号信息
  ALLUSER_URL = "/admin/acl/user/",
  //新增用户
  ADDUSER_URL = "/admin/acl/user/save",
  // 修改用户
  UPDATEUSER_URL = "/admin/acl/user/update",
  //所有角色
  ALLROLE_URL = "/admin/acl/user/toAssign/",
  //给已有的用户分配角色接口
  SETROLE_URL = "/admin/acl/user/doAssignRole",
  //删除某一个
  DELETEUSER_URL = "/admin/acl/user/remove/",
  //批量删除
  DELETEALLUSER_URL = "/admin/acl/user/batchRemove",
}
//获取全部已有用户账号信息
export const reqAllUser = (page: number, limit: number, username: string) =>
  request.get<any, UserResponseData>(
    API.ALLUSER_URL + `${page}/${limit}/?username=${username}`
  );
//新增用户和修改用户
export const reqAddUserOrUpdateUser = (data: Records) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEUSER_URL, data);
  } else {
    return request.post<any, any>(API.ADDUSER_URL, data);
  }
};
//分配角色
export const reqAllRole = (adminId: number) =>
  request.get<any, RoleResponseData>(API.ALLROLE_URL + adminId);
//给已有的用户分配角色接口
export const reqSetRole = (data: SetRoleData) =>
  request.post<any, any>(API.SETROLE_URL, data);
//删除
export const reqRemoveUser = (userId: number) =>
  request.delete<any, any>(API.DELETEUSER_URL + userId);
//批量删除
export const reqRemoveAllUser = (idList: number[]) =>
  request.delete(API.DELETEALLUSER_URL, { data: idList });
